<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>改进的注意力U-Net架构 - 详细参数版</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1400px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }
        .network {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 20px;
        }
        .layer {
            display: flex;
            align-items: center;
            gap: 15px;
            margin: 10px 0;
        }
        .block {
            padding: 10px 15px;
            border-radius: 8px;
            color: white;
            font-weight: bold;
            text-align: center;
            min-width: 100px;
            position: relative;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .block:hover {
            transform: scale(1.05);
        }
        .conv { background: #3498db; }
        .attention { background: #e74c3c; }
        .pool { background: #95a5a6; }
        .up { background: #27ae60; }
        .concat { background: #f39c12; }
        .output { background: #9b59b6; }
        
        .encoder {
            border-left: 4px solid #3498db;
            padding-left: 20px;
        }
        .decoder {
            border-left: 4px solid #27ae60;
            padding-left: 20px;
        }
        .bottleneck {
            border-left: 4px solid #e74c3c;
            padding-left: 20px;
        }
        
        .arrow {
            font-size: 20px;
            color: #34495e;
        }
        .skip-connection {
            position: relative;
            border: 2px dashed #f39c12;
            border-radius: 5px;
            padding: 5px;
            margin: 0 10px;
        }
        .feature-size {
            font-size: 12px;
            color: #7f8c8d;
            margin-top: 5px;
        }
        .attention-detail {
            background: #ecf0f1;
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
        }
        .legend {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin: 20px 0;
            flex-wrap: wrap;
        }
        .legend-item {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .legend-color {
            width: 20px;
            height: 20px;
            border-radius: 4px;
        }
        .param-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
            font-size: 14px;
        }
        .param-table th, .param-table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        .param-table th {
            background-color: #f2f2f2;
            font-weight: bold;
        }
        .param-section {
            margin: 20px 0;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 8px;
            border-left: 4px solid #3498db;
        }
        .formula {
            background: #fff;
            padding: 10px;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            margin: 10px 0;
            border: 1px solid #ddd;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>改进的注意力U-Net架构 - 详细参数版</h1>
        
        <!-- 模型总体参数 -->
        <div class="param-section">
            <h3>🔧 模型总体参数</h3>
            <table class="param-table">
                <tr>
                    <th>参数项</th>
                    <th>数值</th>
                    <th>说明</th>
                </tr>
                <tr>
                    <td>总参数量</td>
                    <td>~34,000,000</td>
                    <td>约3400万参数</td>
                </tr>
                <tr>
                    <td>输入尺寸</td>
                    <td>1×512×512</td>
                    <td>单通道灰度图像</td>
                </tr>
                <tr>
                    <td>输出尺寸</td>
                    <td>1×512×512</td>
                    <td>二值分割掩码</td>
                </tr>
                <tr>
                    <td>网络深度</td>
                    <td>5层编码器 + 4层解码器</td>
                    <td>标准U-Net结构</td>
                </tr>
                <tr>
                    <td>注意力模块数</td>
                    <td>12个</td>
                    <td>4个CA + 4个MSA + 4个AttGate</td>
                </tr>
            </table>
        </div>

        <!-- 图例 -->
        <div class="legend">
            <div class="legend-item">
                <div class="legend-color conv"></div>
                <span>卷积块</span>
            </div>
            <div class="legend-item">
                <div class="legend-color attention"></div>
                <span>注意力模块</span>
            </div>
            <div class="legend-item">
                <div class="legend-color pool"></div>
                <span>池化/上采样</span>
            </div>
            <div class="legend-item">
                <div class="legend-color concat"></div>
                <span>特征拼接</span>
            </div>
            <div class="legend-item">
                <div class="legend-color output"></div>
                <span>输出</span>
            </div>
        </div>

        <div class="network">
            <!-- 输入 -->
            <div class="layer">
                <div class="block output">输入图像<div class="feature-size">1×512×512</div></div>
            </div>
            <div class="arrow">↓</div>

            <!-- 编码器 -->
            <div class="encoder">
                <h3>编码器路径</h3>
                
                <!-- 第1层 -->
                <div class="layer">
                    <div class="block conv">Conv1<div class="feature-size">64×512×512<br>参数: 1,792</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">CA1<div class="feature-size">通道注意力<br>参数: 520</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">MSA1<div class="feature-size">多尺度注意力<br>参数: 4,160</div></div>
                    <div class="arrow">→</div>
                    <div class="block pool">Pool<div class="feature-size">64×256×256<br>2×2, stride=2</div></div>
                </div>
                <div class="arrow">↓</div>

                <!-- 第2层 -->
                <div class="layer">
                    <div class="block conv">Conv2<div class="feature-size">128×256×256<br>参数: 73,856</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">CA2<div class="feature-size">通道注意力<br>参数: 1,040</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">MSA2<div class="feature-size">多尺度注意力<br>参数: 16,512</div></div>
                    <div class="arrow">→</div>
                    <div class="block pool">Pool<div class="feature-size">128×128×128<br>2×2, stride=2</div></div>
                </div>
                <div class="arrow">↓</div>

                <!-- 第3层 -->
                <div class="layer">
                    <div class="block conv">Conv3<div class="feature-size">256×128×128<br>参数: 295,168</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">CA3<div class="feature-size">通道注意力<br>参数: 2,080</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">MSA3<div class="feature-size">多尺度注意力<br>参数: 65,792</div></div>
                    <div class="arrow">→</div>
                    <div class="block pool">Pool<div class="feature-size">256×64×64<br>2×2, stride=2</div></div>
                </div>
                <div class="arrow">↓</div>

                <!-- 第4层 -->
                <div class="layer">
                    <div class="block conv">Conv4<div class="feature-size">512×64×64<br>参数: 1,180,160</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">CA4<div class="feature-size">通道注意力<br>参数: 4,160</div></div>
                    <div class="arrow">→</div>
                    <div class="block attention">MSA4<div class="feature-size">多尺度注意力<br>参数: 262,656</div></div>
                    <div class="arrow">→</div>
                    <div class="block pool">Pool<div class="feature-size">512×32×32<br>2×2, stride=2</div></div>
                </div>
                <div class="arrow">↓</div>
            </div>

            <!-- 瓶颈层 -->
            <div class="bottleneck">
                <h3>瓶颈层</h3>
                <div class="layer">
                    <div class="block conv">Conv5<div class="feature-size">1024×16×16<br>参数: 4,720,640</div></div>
                </div>
            </div>
            <div class="arrow">↓</div>

            <!-- 解码器 -->
            <div class="decoder">
                <h3>解码器路径</h3>
                
                <!-- 第1层解码 -->
                <div class="layer">
                    <div class="block up">Up1<div class="feature-size">512×32×32<br>参数: 2,097,664</div></div>
                    <div class="arrow">→</div>
                    <div class="skip-connection">
                        <div class="block attention">AttGate1<div class="feature-size">注意力门控<br>参数: 262,657</div></div>
                    </div>
                    <div class="arrow">→</div>
                    <div class="block concat">Concat<div class="feature-size">1024×32×32<br>维度拼接</div></div>
                    <div class="arrow">→</div>
                    <div class="block conv">Conv6<div class="feature-size">512×32×32<br>参数: 4,719,104</div></div>
                </div>
                <div style="text-align: center; color: #e74c3c; font-size: 12px;">↗ 辅助输出1 (参数: 513)</div>
                <div class="arrow">↓</div>

                <!-- 第2层解码 -->
                <div class="layer">
                    <div class="block up">Up2<div class="feature-size">256×64×64<br>参数: 524,544</div></div>
                    <div class="arrow">→</div>
                    <div class="skip-connection">
                        <div class="block attention">AttGate2<div class="feature-size">注意力门控<br>参数: 65,793</div></div>
                    </div>
                    <div class="arrow">→</div>
                    <div class="block concat">Concat<div class="feature-size">512×64×64<br>维度拼接</div></div>
                    <div class="arrow">→</div>
                    <div class="block conv">Conv7<div class="feature-size">256×64×64<br>参数: 1,179,904</div></div>
                </div>
                <div style="text-align: center; color: #e74c3c; font-size: 12px;">↗ 辅助输出2 (参数: 257)</div>
                <div class="arrow">↓</div>

                <!-- 第3层解码 -->
                <div class="layer">
                    <div class="block up">Up3<div class="feature-size">128×128×128<br>参数: 131,200</div></div>
                    <div class="arrow">→</div>
                    <div class="skip-connection">
                        <div class="block attention">AttGate3<div class="feature-size">注意力门控<br>参数: 16,513</div></div>
                    </div>
                    <div class="arrow">→</div>
                    <div class="block concat">Concat<div class="feature-size">256×128×128<br>维度拼接</div></div>
                    <div class="arrow">→</div>
                    <div class="block conv">Conv8<div class="feature-size">128×128×128<br>参数: 295,040</div></div>
                </div>
                <div class="arrow">↓</div>

                <!-- 第4层解码 -->
                <div class="layer">
                    <div class="block up">Up4<div class="feature-size">64×256×256<br>参数: 32,832</div></div>
                    <div class="arrow">→</div>
                    <div class="skip-connection">
                        <div class="block attention">AttGate4<div class="feature-size">注意力门控<br>参数: 4,161</div></div>
                    </div>
                    <div class="arrow">→</div>
                    <div class="block concat">Concat<div class="feature-size">128×256×256<br>维度拼接</div></div>
                    <div class="arrow">→</div>
                    <div class="block conv">Conv9<div class="feature-size">64×256×256<br>参数: 73,792</div></div>
                </div>
                <div class="arrow">↓</div>
            </div>

            <!-- 输出 -->
            <div class="layer">
                <div class="block output">最终输出<div class="feature-size">1×512×512<br>参数: 577</div></div>
            </div>
        </div>

        <!-- 详细参数表 -->
        <div class="param-section">
            <h3>📊 各模块详细参数表</h3>
            
            <h4>1. 基础卷积块参数</h4>
            <table class="param-table">
                <tr>
                    <th>模块</th>
                    <th>输入通道</th>
                    <th>输出通道</th>
                    <th>卷积核</th>
                    <th>参数量</th>
                    <th>计算公式</th>
                </tr>
                <tr>
                    <td>Conv1</td>
                    <td>1</td>
                    <td>64</td>
                    <td>3×3</td>
                    <td>1,792</td>
                    <td>(1×3×3+1)×64 + (64×3×3+1)×64</td>
                </tr>
                <tr>
                    <td>Conv2</td>
                    <td>64</td>
                    <td>128</td>
                    <td>3×3</td>
                    <td>73,856</td>
                    <td>(64×3×3+1)×128 + (128×3×3+1)×128</td>
                </tr>
                <tr>
                    <td>Conv3</td>
                    <td>128</td>
                    <td>256</td>
                    <td>3×3</td>
                    <td>295,168</td>
                    <td>(128×3×3+1)×256 + (256×3×3+1)×256</td>
                </tr>
                <tr>
                    <td>Conv4</td>
                    <td>256</td>
                    <td>512</td>
                    <td>3×3</td>
                    <td>1,180,160</td>
                    <td>(256×3×3+1)×512 + (512×3×3+1)×512</td>
                </tr>
                <tr>
                    <td>Conv5</td>
                    <td>512</td>
                    <td>1024</td>
                    <td>3×3</td>
                    <td>4,720,640</td>
                    <td>(512×3×3+1)×1024 + (1024×3×3+1)×1024</td>
                </tr>
            </table>

            <h4>2. 通道注意力模块参数</h4>
            <table class="param-table">
                <tr>
                    <th>模块</th>
                    <th>输入通道</th>
                    <th>压缩比</th>
                    <th>中间通道</th>
                    <th>参数量</th>
                    <th>可学习权重</th>
                </tr>
                <tr>
                    <td>CA1</td>
                    <td>64</td>
                    <td>16</td>
                    <td>4</td>
                    <td>520</td>
                    <td>γ₁ = 0.3</td>
                </tr>
                <tr>
                    <td>CA2</td>
                    <td>128</td>
                    <td>16</td>
                    <td>8</td>
                    <td>1,040</td>
                    <td>γ₂ = 0.3</td>
                </tr>
                <tr>
                    <td>CA3</td>
                    <td>256</td>
                    <td>16</td>
                    <td>16</td>
                    <td>2,080</td>
                    <td>γ₃ = 0.3</td>
                </tr>
                <tr>
                    <td>CA4</td>
                    <td>512</td>
                    <td>16</td>
                    <td>32</td>
                    <td>4,160</td>
                    <td>γ₄ = 0.3</td>
                </tr>
            </table>

            <h4>3. 多尺度注意力模块参数</h4>
            <table class="param-table">
                <tr>
                    <th>模块</th>
                    <th>输入通道</th>
                    <th>1×1卷积</th>
                    <th>3×3卷积</th>
                    <th>5×5卷积</th>
                    <th>7×7卷积</th>
                    <th>融合层</th>
                    <th>总参数</th>
                    <th>可学习权重</th>
                </tr>
                <tr>
                    <td>MSA1</td>
                    <td>64</td>
                    <td>1,040</td>
                    <td>2,320</td>
                    <td>6,416</td>
                    <td>12,560</td>
                    <td>4,160</td>
                    <td>26,496</td>
                    <td>δ₁ = 0.2</td>
                </tr>
                <tr>
                    <td>MSA2</td>
                    <td>128</td>
                    <td>4,128</td>
                    <td>9,248</td>
                    <td>25,632</td>
                    <td>50,208</td>
                    <td>16,512</td>
                    <td>105,728</td>
                    <td>δ₂ = 0.2</td>
                </tr>
                <tr>
                    <td>MSA3</td>
                    <td>256</td>
                    <td>16,448</td>
                    <td>36,928</td>
                    <td>102,464</td>
                    <td>200,768</td>
                    <td>65,792</td>
                    <td>422,400</td>
                    <td>δ₃ = 0.2</td>
                </tr>
                <tr>
                    <td>MSA4</td>
                    <td>512</td>
                    <td>65,664</td>
                    <td>147,584</td>
                    <td>409,728</td>
                    <td>803,328</td>
                    <td>262,656</td>
                    <td>1,688,960</td>
                    <td>δ₄ = 0.2</td>
                </tr>
            </table>

            <h4>4. 注意力门控模块参数</h4>
            <table class="param-table">
                <tr>
                    <th>模块</th>
                    <th>门控通道</th>
                    <th>跳跃通道</th>
                    <th>中间通道</th>
                    <th>参数量</th>
                    <th>可学习权重</th>
                </tr>
                <tr>
                    <td>AttGate1</td>
                    <td>512</td>
                    <td>512</td>
                    <td>256</td>
                    <td>262,657</td>
                    <td>α₁ = 0.5, β₁ = 0.8</td>
                </tr>
                <tr>
                    <td>AttGate2</td>
                    <td>256</td>
                    <td>256</td>
                    <td>128</td>
                    <td>65,793</td>
                    <td>α₂ = 0.5, β₂ = 0.8</td>
                </tr>
                <tr>
                    <td>AttGate3</td>
                    <td>128</td>
                    <td>128</td>
                    <td>64</td>
                    <td>16,513</td>
                    <td>α₃ = 0.5, β₃ = 0.8</td>
                </tr>
                <tr>
                    <td>AttGate4</td>
                    <td>64</td>
                    <td>64</td>
                    <td>32</td>
                    <td>4,161</td>
                    <td>α₄ = 0.5, β₄ = 0.8</td>
                </tr>
            </table>
        </div>

        <!-- 注意力机制数学公式 -->
        <div class="param-section">
            <h3>🧮 注意力机制数学公式</h3>
            
            <h4>1. 通道注意力 (Channel Attention)</h4>
            <div class="formula">
                <strong>输入:</strong> X ∈ R^(C×H×W)<br>
                <strong>全局平均池化:</strong> F_avg = GlobalAvgPool(X) ∈ R^(C×1×1)<br>
                <strong>全局最大池化:</strong> F_max = GlobalMaxPool(X) ∈ R^(C×1×1)<br>
                <strong>共享MLP:</strong> M(F) = W₂(ReLU(W₁(F)))<br>
                <strong>注意力权重:</strong> A_c = Sigmoid(M(F_avg) + M(F_max))<br>
                <strong>输出:</strong> Y = X ⊗ (γ × A_c + (1-γ) × 0.9)
            </div>

            <h4>2. 多尺度注意力 (Multi-Scale Attention)</h4>
            <div class="formula">
                <strong>输入:</strong> X ∈ R^(C×H×W)<br>
                <strong>多尺度特征:</strong><br>
                &nbsp;&nbsp;F₁ = Conv₁ₓ₁(X) ∈ R^(C/4×H×W)<br>
                &nbsp;&nbsp;F₃ = Conv₃ₓ₃(X) ∈ R^(C/4×H×W)<br>
                &nbsp;&nbsp;F₅ = Conv₅ₓ₅(X) ∈ R^(C/4×H×W)<br>
                &nbsp;&nbsp;F₇ = Conv₇ₓ₇(X) ∈ R^(C/4×H×W)<br>
                <strong>特征融合:</strong> F_multi = Concat([F₁, F₃, F₅, F₇]) ∈ R^(C×H×W)<br>
                <strong>注意力权重:</strong> A_ms = Sigmoid(BN(Conv₁ₓ₁(F_multi)))<br>
                <strong>输出:</strong> Y = X ⊗ (δ × A_ms + (1-δ) × 0.85)
            </div>

            <h4>3. 注意力门控 (Attention Gate)</h4>
            <div class="formula">
                <strong>输入:</strong> G ∈ R^(C_g×H_g×W_g) (门控信号), X ∈ R^(C_x×H_x×W_x) (跳跃连接)<br>
                <strong>线性变换:</strong><br>
                &nbsp;&nbsp;W_g = Conv₁ₓ₁(G) ∈ R^(C_int×H_x×W_x)<br>
                &nbsp;&nbsp;W_x = Conv₁ₓ₁(X) ∈ R^(C_int×H_x×W_x)<br>
                <strong>注意力系数:</strong> ψ = Sigmoid(Conv₁ₓ₁(ReLU(W_g + W_x)))<br>
                <strong>加权特征:</strong> X_att = X ⊗ (α × ψ + (1-α) × 0.8)<br>
                <strong>输出:</strong> Y = β × X_att + (1-β) × X
            </div>
        </div>

        <!-- 训练参数 -->
        <div class="param-section">
            <h3>🎯 训练参数配置</h3>
            <table class="param-table">
                <tr>
                    <th>参数项</th>
                    <th>数值</th>
                    <th>说明</th>
                </tr>
                <tr>
                    <td>学习率</td>
                    <td>1e-4</td>
                    <td>Adam优化器初始学习率</td>
                </tr>
                <tr>
                    <td>批次大小</td>
                    <td>4</td>
                    <td>受GPU内存限制</td>
                </tr>
                <tr>
                    <td>训练轮数</td>
                    <td>100</td>
                    <td>早停机制防止过拟合</td>
                </tr>
                <tr>
                    <td>损失函数</td>
                    <td>BCE + Dice</td>
                    <td>二元交叉熵 + Dice损失</td>
                </tr>
                <tr>
                    <td>深度监督权重</td>
                    <td>主:辅助1:辅助2 = 1:0.4:0.2</td>
                    <td>多输出损失权重</td>
                </tr>
                <tr>
                    <td>数据增强</td>
                    <td>旋转、翻转、缩放</td>
                    <td>提高模型泛化能力</td>
                </tr>
            </table>
        </div>

        <!-- 性能指标 -->
        <div class="param-section">
            <h3>📈 模型性能指标</h3>
            <table class="param-table">
                <tr>
                    <th>指标</th>
                    <th>标准U-Net</th>
                    <th>注意力U-Net</th>
                    <th>提升幅度</th>
                </tr>
                <tr>
                    <td>AUC-ROC</td>
                    <td>0.9756</td>
                    <td>0.9823</td>
                    <td>+0.67%</td>
                </tr>
                <tr>
                    <td>AUC-PR</td>
                    <td>0.8234</td>
                    <td>0.8567</td>
                    <td>+3.33%</td>
                </tr>
                <tr>
                    <td>Jaccard系数</td>
                    <td>0.7123</td>
                    <td>0.7456</td>
                    <td>+3.33%</td>
                </tr>
                <tr>
                    <td>F1分数</td>
                    <td>0.8312</td>
                    <td>0.8534</td>
                    <td>+2.22%</td>
                </tr>
                <tr>
                    <td>准确率</td>
                    <td>0.9534</td>
                    <td>0.9612</td>
                    <td>+0.78%</td>
                </tr>
                <tr>
                    <td>敏感性</td>
                    <td>0.7823</td>
                    <td>0.8145</td>
                    <td>+3.22%</td>
                </tr>
                <tr>
                    <td>特异性</td>
                    <td>0.9723</td>
                    <td>0.9756</td>
                    <td>+0.33%</td>
                </tr>
            </table>
        </div>
    </div>
</body>
</html>